package com.tanhua.sso.service;

import com.tanhua.sso.mapper.UserMapper;
import com.tanhua.sso.pojo.User;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserService {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
  private   UserMapper userMapper;

    //校验手机号，发送验证码

//   验证验证码进行登录

    public String login(String phone,String code) {
        String token = "查无此人";
        Boolean isNew = false;
        String redisKey = "CODE_CHECK_"+phone;
        String code_value = this.redisTemplate.opsForValue().get(redisKey);
        if (code.equals(code_value)){
            token = "我是真实用户";
            isNew = true;
            User user = User.builder().mobile(phone).build();
            userMapper.insert(user);
            return token + "|" + isNew;
        }
        return token + "|" + isNew;
    }

}
